package at.jaki.ubb.crawling.stlib.filters;

import java.util.HashSet;
import java.util.Set;

import at.jaki.ubb.crawling.api.filters.FilterResult;
import at.jaki.ubb.crawling.api.filters.TargetFilter;
import at.jaki.ubb.crawling.model.Target;

/**
 * Ensures that every target will only be used at most once, during the
 * application
 * 
 * @author Attila Jakabfi
 * 
 */
public class UniqueTargetFilter implements TargetFilter {

	private Set<String> usedIds = new HashSet<String>();

	@Override
	public FilterResult doFilter(Target<?> t) {
		String id = t.getId();
		if (usedIds.contains(id)) {
			return FilterResult.DROP;
		} else {
			usedIds.add(id);
			return FilterResult.CONTINIUE;
		}
	}

	@Override
	public void reset() {
		usedIds.clear();
	}

}
